package com.kwdb.server.storage;

import com.kwdb.grpc.DataPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.concurrent.atomic.AtomicLong;

/**
 * RocksDB存储引擎实现
 */
public class RocksDBStorageEngine implements StorageEngine {
    
    private static final Logger logger = LoggerFactory.getLogger(RocksDBStorageEngine.class);
    private final AtomicLong writeCount = new AtomicLong(0);
    
    public RocksDBStorageEngine() {
        logger.info("RocksDB存储引擎初始化");
    }
    
    @Override
    public void write(DataPoint dataPoint) throws Exception {
        // 模拟写入
        writeCount.incrementAndGet();
        logger.debug("写入数据点: {}, 总写入数: {}", 
            dataPoint.getMeasurement(), writeCount.get());
    }
    
    @Override
    public void writeBatch(List<DataPoint> dataPoints) throws Exception {
        // 模拟批量写入
        writeCount.addAndGet(dataPoints.size());
        logger.info("批量写入 {} 条数据，总写入数: {}", 
            dataPoints.size(), writeCount.get());
    }
    
    @Override
    public void shutdown() {
        logger.info("RocksDB存储引擎关闭，总写入数: {}", writeCount.get());
    }
}

